package edu.mobbuzz.main;

import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import edu.mobbuzz.page.authorization.Login;
import edu.mobbuzz.page.menu.InboxMenu;
import javax.microedition.midlet.*;

public class MainMenu extends MIDlet implements ActionListener {
    private Form mainForm;
   
    
    public void openRSSChannel() {
       
    }

    public void openInbox() {
       
    }

    public void openMenu() {

    }

    public void openCategory() {

    }

    public void openContact() {

    }
    
    
    public void startScheduler() {
        
    }
    protected void startApp(){
        Display.init(this);
        mainForm = new Form();    
        try {
            Resources r = Resources.open("/mobbuzz.res");
            UIManager.getInstance().setThemeProps(r.getTheme("mobbuzz"));
           
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        
        try{
            System.gc();
            Login loginPage = new Login();
            mainForm = loginPage.getLoginPage();
            mainForm.setCommandListener(this);
            mainForm.show();
            
        }catch(Exception e){
           System.gc();
        }
        
            
           
      
    }
    
    protected void pauseApp() {
        
    }

    protected void destroyApp(boolean arg0){
        
    }

    public void actionPerformed(ActionEvent ev) {
        
        if(ev.getCommand().getCommandName().equals("Exit")){
            destroyApp(true);
	    notifyDestroyed();
            
        }else if(ev.getCommand().getCommandName().equals("Go Offline")){
            InboxMenu inboxPage = new InboxMenu();
            inboxPage.setExitCmd(mainForm.getBackCommand());
            inboxPage.setActionlistener(this);
            inboxPage.showPage();
            
        }else if(ev.getCommand().getCommandName().equals("Go Online")){
            mainForm.show();
        }else if(ev.getCommand().getCommandName().equals("Go Offline")){
            InboxMenu inboxMenu = new InboxMenu();
            inboxMenu.setExitCmd(mainForm.getBackCommand());
            inboxMenu.setActionlistener(this);
            inboxMenu.showPage();
        }
       
    }
    
   
}
